package com.clothes.warehouse.db.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.example.test2.db.converter.StringConverter;
import java.util.List;

import com.example.test2.db.entity.User;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "USER".
*/
public class UserDao extends AbstractDao<User, Long> {

    public static final String TABLENAME = "USER";

    /**
     * Properties of entity User.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Phone = new Property(1, String.class, "phone", false, "PHONE");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property ShopName = new Property(3, String.class, "shopName", false, "SHOP_NAME");
        public final static Property Pwd = new Property(4, String.class, "pwd", false, "PWD");
        public final static Property Date = new Property(5, String.class, "date", false, "DATE");
        public final static Property Msg = new Property(6, String.class, "msg", false, "MSG");
        public final static Property Path = new Property(7, String.class, "path", false, "PATH");
        public final static Property Attention = new Property(8, boolean.class, "attention", false, "ATTENTION");
        public final static Property Boy = new Property(9, boolean.class, "boy", false, "BOY");
        public final static Property MsgList = new Property(10, String.class, "msgList", false, "MSG_LIST");
    }

    private final StringConverter msgListConverter = new StringConverter();

    public UserDao(DaoConfig config) {
        super(config);
    }
    
    public UserDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"USER\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"PHONE\" TEXT," + // 1: phone
                "\"NAME\" TEXT," + // 2: name
                "\"SHOP_NAME\" TEXT," + // 3: shopName
                "\"PWD\" TEXT," + // 4: pwd
                "\"DATE\" TEXT," + // 5: date
                "\"MSG\" TEXT," + // 6: msg
                "\"PATH\" TEXT," + // 7: path
                "\"ATTENTION\" INTEGER NOT NULL ," + // 8: attention
                "\"BOY\" INTEGER NOT NULL ," + // 9: boy
                "\"MSG_LIST\" TEXT);"); // 10: msgList
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_USER_PHONE ON \"USER\"" +
                " (\"PHONE\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"USER\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, User entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String phone = entity.getPhone();
        if (phone != null) {
            stmt.bindString(2, phone);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String shopName = entity.getShopName();
        if (shopName != null) {
            stmt.bindString(4, shopName);
        }
 
        String pwd = entity.getPwd();
        if (pwd != null) {
            stmt.bindString(5, pwd);
        }
 
        String date = entity.getDate();
        if (date != null) {
            stmt.bindString(6, date);
        }
 
        String msg = entity.getMsg();
        if (msg != null) {
            stmt.bindString(7, msg);
        }
 
        String path = entity.getPath();
        if (path != null) {
            stmt.bindString(8, path);
        }
        stmt.bindLong(9, entity.getAttention() ? 1L: 0L);
        stmt.bindLong(10, entity.getBoy() ? 1L: 0L);
 
        List msgList = entity.getMsgList();
        if (msgList != null) {
            stmt.bindString(11, msgListConverter.convertToDatabaseValue(msgList));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, User entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String phone = entity.getPhone();
        if (phone != null) {
            stmt.bindString(2, phone);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String shopName = entity.getShopName();
        if (shopName != null) {
            stmt.bindString(4, shopName);
        }
 
        String pwd = entity.getPwd();
        if (pwd != null) {
            stmt.bindString(5, pwd);
        }
 
        String date = entity.getDate();
        if (date != null) {
            stmt.bindString(6, date);
        }
 
        String msg = entity.getMsg();
        if (msg != null) {
            stmt.bindString(7, msg);
        }
 
        String path = entity.getPath();
        if (path != null) {
            stmt.bindString(8, path);
        }
        stmt.bindLong(9, entity.getAttention() ? 1L: 0L);
        stmt.bindLong(10, entity.getBoy() ? 1L: 0L);
 
        List msgList = entity.getMsgList();
        if (msgList != null) {
            stmt.bindString(11, msgListConverter.convertToDatabaseValue(msgList));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public User readEntity(Cursor cursor, int offset) {
        User entity = new User( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // phone
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // shopName
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // pwd
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // date
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // msg
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // path
            cursor.getShort(offset + 8) != 0, // attention
            cursor.getShort(offset + 9) != 0, // boy
            cursor.isNull(offset + 10) ? null : msgListConverter.convertToEntityProperty(cursor.getString(offset + 10)) // msgList
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, User entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setPhone(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setShopName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPwd(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setMsg(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setPath(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setAttention(cursor.getShort(offset + 8) != 0);
        entity.setBoy(cursor.getShort(offset + 9) != 0);
        entity.setMsgList(cursor.isNull(offset + 10) ? null : msgListConverter.convertToEntityProperty(cursor.getString(offset + 10)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(User entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(User entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(User entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
